/*
 * Level1.cpp
 *
 *  Created on: Jul 13, 2009
 *      Author: scott
 */
#include <allegro.h>
#include "Level1.h"

#include <ode/ode.h>

#include "ObjectVisitor.h"
#include "FPSCamera.h"
#include "Vacuum.h"
#include "World.h"
#include "Player.h"
#include "Dust.h"

// weapons
#include "Blower.h"
#include "Broom.h"

Level1::Level1(SAMPLE * new_sample,SAMPLE * new_sample2)
{
	this->sample = new_sample;
	this->sample2 = new_sample2;
}

Level1::~Level1() {

}

void Level1::switchTo()
{
	// create a new scene graph
	root = new SceneGraphNode(NULL, true);

	// create the world
	world = new World(root,sample2);

	// make a camera
	camera = new FPSCamera(root, true);

	// camera projection options
	camera->setFov(45.0f);
	camera->setAspectRatio(640.0f/480.0f);
	camera->setNearClip(0.01f);
	camera->setFarClip(20000.0f);
	camera->applyProj();

	// camera view options
	camera->setTranslation(irr::core::vector3df(0, 0, -5.0f));
	camera->setLookAt(irr::core::vector3df(0.0f, 0.0f, 0.0f));
	camera->setUp(irr::core::vector3df(0, 1.0f, 0));

	// create the player
	Player * player = new Player(world, camera, true);
	player->addWeapon(new Broom(world, player, true), 1);
	player->addWeapon(new Blower(sample, false, player, true), 9);
	player->addWeapon(new Blower(sample, true, player, true), 0);

	// the objects that make up the game
	//Vacuum * vacuumStationery = new Vacuum(root);
	//Vacuum * vacuum = new Vacuum(camera);
	//vacuum->setTranslation(irr::core::vector3df(0, 0, 2.0f));

	srand(time(0));
	for (int i = 0; i < 100; i++)
	{
		Dust * dust = new Dust(world, root, "media/cube.3ds", true);
		dust->setTranslation(irr::core::vector3df(rand()%20-10, -0.5, rand()%20-10));
		//dust->setScale(irr::core::vector3df(0.5f,0.5f,0.5f));
		dust->reverseUpdate();
	}
}

void Level1::update()
{
	world->update();
	camera->update();
}

void Level1::switchFrom()
{
	// delete everything
	delete root;
}

int Level1::countDust()
{
	int count = 0;
	for (irr::core::list<Dust *>::Iterator iter = Dust::dust.begin(); iter != Dust::dust.end(); iter++)
	{
		irr::core::vector3df pos = (*iter)->getTranslation();
		if (pos.X > -10 && pos.X < 10 && pos.Z > -10 && pos.Z < 10 && (*iter)->getVisible())
			count++;

	}
	cout << "Number of boxes in space: " << count << endl;

}

